package com.applet.applet_shangcheng.controller;

import com.applet.applet_shangcheng.entity.TheProblem;
import com.applet.applet_shangcheng.entity.TheRules;
import com.applet.applet_shangcheng.service.TheRulesService;
import com.applet.applet_shangcheng.utlis.PageResult;
import com.applet.applet_shangcheng.utlis.QueryPageBean;
import com.applet.applet_shangcheng.utlis.Result;
import com.applet.applet_shangcheng.utlis.StatusCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/theRules")
@CrossOrigin
@Api(value="规则管理",tags={"规则管理"})
public class TheRulesController {

    @Autowired
    private TheRulesService theRulesService;
    @ApiOperation(value="WX_查询规则内容")
    @GetMapping("/WXselectTheRules")
    public Result selectTheRules() {
        List<TheRules> theRulesList = theRulesService.selectTheRules();
        return new Result(true, StatusCode.OK, "查询成功", theRulesList);
    }
    @ApiOperation(value="PC_分页查询规则内容")
    @PostMapping("/findTheProblemS")
    public PageResult findTheProblemS(@RequestBody QueryPageBean queryPageBean) {
        PageResult pageResult = theRulesService.findTheProblemS(queryPageBean.getQueryString(), queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
        return pageResult;
    }
    @ApiOperation(value="WX_根据synopsis商场条例成功")
    @GetMapping("/findTheProblem/{synopsis}")
    public Result findTheProblem(@PathVariable("synopsis") String synopsis) {
        TheProblem theProblem = theRulesService.findTheProblem(synopsis);
        return new Result(true, StatusCode.OK, "商场条例成功", theProblem);
    }
    @ApiOperation(value="WX_根据id商场条例成功")
    @GetMapping("/findByTheRules/{id}")
    public Result findByTheRules(@PathVariable("id") String id) {
        TheRules theRules = theRulesService.findByTheRules(id);
        return new Result(true, StatusCode.OK, "商场条例成功", theRules);
    }

    ;
    @ApiOperation(value="PC_分页查询商场条例")
    @PostMapping("/findAll")
    public PageResult findAll(@RequestBody QueryPageBean queryPageBean) {
        PageResult pageResult = theRulesService.findAll(queryPageBean.getQueryString(), queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
        return pageResult;
    }
    @ApiOperation(value="PC_修改商场条例")
    @PostMapping("/updateTheProblem")
    public Result updateTheProblem(@RequestBody TheProblem theProblem) {
        int result = theRulesService.updateTheProblem(theProblem);
        if (result > 0) {
            return new Result(true, StatusCode.OK, "商场条例修改成功");
        }
        return new Result(false, StatusCode.ERROR, "商场条例修改失败");
    }

    ;


    @ApiOperation(value="PC_添加推荐")
    @PostMapping("/insertTheRules")
    public Result insertTheRules(@RequestBody TheRules theRules) {
        int rules = theRulesService.insertTheRules(theRules);
        if (rules > 0) {
            return new Result(true, StatusCode.OK, "推荐信息添加成功", theRules);
        }
        return new Result(false, StatusCode.ERROR, "推荐信息添加失败");
    }
    @ApiOperation(value="PC_修改推荐")
    @PostMapping("/updateTheRules")
    public Result updateTheRules(@RequestBody TheRules theRules) {
        int rules = theRulesService.updateTheRules(theRules);
        if (rules > 0) {
            return new Result(true, StatusCode.OK, "推荐信息修改成功");
        }
        return new Result(false, StatusCode.ERROR, "推荐信息修改失败");
    }
    @ApiOperation(value="PC_修改推荐状态")
    @GetMapping("/updateStatus/{id}/{status}")
    public Result updateStatus(@PathVariable("id") int id,
                               @PathVariable("status") int status) {
        int status1 = theRulesService.updateStatus(id, status);
        if (status1 > 0) {
            return new Result(true, StatusCode.OK, "推荐信息状态修改成功");
        }
        return new Result(false, StatusCode.ERROR, "推荐信息状态修改失败");
    }
    @ApiOperation(value="PC_推荐信息删除")
    @GetMapping("/deleteTheRules/{id}")
    public Result deleteTheRules(@PathVariable("id") int id) {
        int deleteTheRules = theRulesService.deleteTheRules(id);
        if (deleteTheRules > 0) {
            return new Result(true, StatusCode.OK, "推荐信息删除成功");
        }
        return new Result(false, StatusCode.ERROR, "推荐信息删除失败");
    }

    ;
}
